/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @author: jin Chen 
 * @date: Aug 27, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.toolkits.colorpalette.v1;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.Serializable;

public class RecentSwatchPanel extends SwatchPanel {

    protected void initValues() {
        swatchSize = new Dimension(15,15);// UIManager.getDimension("ColorChooser.swatchesRecentSwatchSize");
	    numSwatches = new Dimension( 4, 3 );
        gap = new Dimension(3, 3);
        outlineSquare=true;
    }


    protected void initColors() {
        Color defaultRecentColor =Color.gray ;// UIManager.getColor("ColorChooser.swatchesDefaultRecentColor");
        int numColors = numSwatches.width * numSwatches.height;

	    colors = new Color[numColors];
	    for (int i = 0; i < numColors ; i++) {
	    colors[i] = defaultRecentColor;
	    }
    }

    public void setMostRecentColor(Color c) {

	System.arraycopy( colors, 0, colors, 1, colors.length-1);
        colors[0] = c;
	repaint();
    }
    public class RecentSwatchListener extends MouseAdapter implements Serializable {
        public void mousePressed(MouseEvent e) {
           int clickCount= e.getClickCount();
           if(clickCount==1){
	        Color color = getColorForLocation(e.getX(), e.getY());
	        System.out.println("select color:"+color);
           }
           else if(clickCount==2){
               Color c=JColorChooser.showDialog(RecentSwatchPanel.this,"Please choose a color",Color.white );
               setMostRecentColor(c);
           }
        }

	}
   

}

